﻿using System;
public class Animal
{
    public virtual void Voice()
    {
        Console.WriteLine("动物发出声音");
    }
}
public class Cat : Animal
{
    public override void Voice()
    {
        Console.WriteLine("喵喵喵");
    }
}
public class Pig : Animal
{
    public override void Voice()
    {
        Console.WriteLine("哼哼哼");
    }
}
public class Dog : Animal
{
    public override void Voice()
    {
        Console.WriteLine("汪汪汪");
    }
}
public class Store
{
    public Animal GetInstance(string animalType)
    {
        switch (animalType.ToLower())
        {
            case "dog":
                return new Dog();
            case "pig":
                return new Pig();
            default:
                return new Cat();
        }
    }
}
class Program
{
    static void Main(string[] args)
    {
        Store petStore = new Store();

        Console.WriteLine("欢迎来到宠物店！");
        Console.WriteLine("请输入您想获取的动物类型 (dog, pig, 或其他):");

        string input = Console.ReadLine();
        Animal animal = petStore.GetInstance(input);

        Console.WriteLine($"您获得了{animal.GetType().Name}，它的声音是：");
        animal.Voice();

        Console.WriteLine("\n宠物店所有动物演示：");

        Animal dog = petStore.GetInstance("dog");
        Console.Write("狗: ");
        dog.Voice();

        Animal pig = petStore.GetInstance("pig");
        Console.Write("猪: ");
        pig.Voice();

        Animal cat = petStore.GetInstance("cat");
        Console.Write("猫: ");
        cat.Voice();

        Animal unknown = petStore.GetInstance("unknown");
        Console.Write("未知动物: ");
        unknown.Voice();

        Console.WriteLine("\n按任意键退出...");
        Console.ReadKey();
    }
}